נתונות שתי הפעולות IsExist1 ו-IsExist2.
נתונות שתי הפעולות IsExist1 ו-IsExist2.
language_variants: codeBlock:
public static boolean isExist1(Stack<Integer> st, int x){
while(!st.isEmpty()){
if(st.pop()==x) return true;
}
return false;
}
public static boolean isExist2(Stack<Integer> st, int x){
Stack<Integer> temp = new Stack<Integer>();
boolean f = false;
while(!st.isEmpty()){
if(st.top()==x) f = true;
temp.push(st.pop());
}
while(!temp.isEmpty()) {
st.push(temp.pop());
}
return f;
}
הסבירו מה מבצעת כל אחת מהפעולות, מה ההבדל ביניהן ומהי הסיבוכיות של כל אחת מהן.
public static boolean containsAll(Stack<Integer> st1, Stack<Integer> st2)
כתבו פעולה המקבלת שתי מחסניות שלמים st1 ו-st2. הפעולה תבדוק אם כל האיברים של st1 נמצאים במחסנית st2 גם כן. אם כן, הפעולה תחזיר ערך true, ואם לא – הפעולה תחזיר ערך false.
example: descriptionHebrew: לדוגמה, עבור המחסניות שלפניכם תחזיר הפעולה ערך true:
st1: [2, 3, 10, 7]
st2: [3, 14, 2, 2, 3, 7, 10, 2, 10]
public static boolean containsInOrder(Stack<Integer> st1, Stack<Integer> st2)
כתבו פעולה המקבלת שתי מחסניות שלמים st1 ו-st2. הפעולה תבדוק אם כל האיברים של st1 נמצאים במחסנית st2 באותו הסדר. אם כן, הפעולה תחזיר ערך true (באותו הסדר), ואם לא – הפעולה תחזיר ערך false.
example: descriptionHebrew: לדוגמה, נתונות דוגמאות st2 עם חלק מהאיברים מודגשים/נטויים כדי להמחיש התאמה עוקבת מול st1 (ראו קובץ המקור לוודאות מלאה על אילו תאים מסומנים).
confidence: MEDIUM-LOW — this example's exact bold/italic highlighting semantics (which cells denote the matched subsequence vs which denote the true/false verdict) could not be transcribed with full confidence from the rendered image; re-verify directly against the source PDF before using as a solve-oracle input.
public static boolean isSubStack(Stack<Integer> st1, Stack<Integer> st2)
כתבו פעולה המקבלת שתי מחסניות שלמים st1 ו-st2. הפעולה תבדוק אם המחסנית st1 היא תת-מחסנית של st2 (כלומר, אם כל האיברים של המחסנית st1 נמצאים במחסנית st2 ברצף ובאותו הסדר). אם כן, הפעולה תחזיר ערך true, ואם לא – הפעולה תחזיר ערך false.
example: > confidence: MEDIUM-LOW — same caveat as part ג': the illustrative grid with highlighted cells is transcribed at reduced confidence.
מהי הסיבוכיות של כל אחת מהפעולות שכתבתם? הסבירו את תשובתכם.
שאלות ותגובות על השאלה
🎓 לא הבנתם משהו? קבלו הסבר נוסף ממרצה לתכנות
שאלו כאן — ותקבלו מענה מוסמך.