IT, Programming, & Web Development › Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 3: [Algorithms] – Linear Search, Binary Search, Bubble Sort, Selection Sort, Recursion, Merge Sort › How i, j and voter, rank differ in dimension despite of integer data type
- This topic is empty.
-
AuthorPosts
-
December 5, 2022 at 9:16 am #943
Although int i and int j as well int voter and int rank are all integer data type, there is a dimensional difference between first two (int i and int j) and last two (int voter and int rank).
It should be because voter and rank are getting values based on two for loops involving i and j. So we can call voter and rank as two dimensional arrays. Although no where could I see voter and rank defined as arrays! It is int preferences that includes voter and rank:
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”yes” line-numbers=”yes” bg-color=”#abb8c3″ theme=”dark” language=”clike” wrapped=”yes” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
// preferences[i][j] is jth preference for voter i int preferences[MAX_VOTERS][MAX_CANDIDATES];
[/dm_code_snippet]
Initially, when I tried to use printf (line 141), I did not expect two dimensional values (01,02,03…), given voter defined as int type (missed my attention that arrays too can be of int type).
printf(“voter no.: %i”, voter);
So while on first look, it appeared to me that i,j and voter, rank are synonymous, they are not.
While int preferences by definition two dimensional, interesting to see how voter and rank too are getting transformed as two dimensional by application of for loops (involving i and j).
Note: The reason I have posted is if anyone can correct or add to what I observed.
Reply
https://edstem.org/us/courses/176/discussion/2260175?comment=5163337[learn_press_profile]
-
AuthorPosts
- You must be logged in to reply to this topic.